<template>
	<!-- h5端 -->
	<!-- #ifndef APP-PLUS -->
	<web-view style="width: 100%;height: 100%;" :src="Mapview.webUrl.value"></web-view>
	<!-- #endif -->
	<!-- app端 -->
	<!-- #ifdef APP-PLUS -->
	<web-view :fullscreen="false" :src="Mapview.webUrl.value"></web-view>
	<!-- #endif -->
</template>
 
<script setup>
import { onMounted, getCurrentInstance, reactive, ref } from 'vue'
import { onLoad, onShow, onHide } from "@dcloudio/uni-app"

//地图地址
let Mapview = {
	webUrl: ref('/static/html/gMap.html'),
}

//传入maker的数据 需要动态获取这里演示所以写死
function getStationData (lng, lat) {
	const stationMarkersData = [{
			longitude: 113.339688,
			latitude: 23.16154,
			name: '11111111111111'
		},
		{
			longitude: 113.196217,
			latitude: 23.070792,
			name: '22222222222222'
		},
		{
			longitude: 113.327379,
			latitude: 23.145002,
			name: '33333333333333'
		},
		{
			longitude: 113.264431,
			latitude: 23.056863,
			name: '44444444444444'
		},
		{
			longitude: 113.385708,
			latitude: 23.171367,
			name: '55555555555555'
		}
	];
	stationMarkersData.forEach((item, index) => {
		let iconPath = '../../static/location-blue.png'
		let id = index
		item = { ...item, id, iconPath }
	})
	let params = encodeURIComponent(JSON.stringify(stationMarkersData))
	let timeStamp = new Date().getTime()
	Mapview.webUrl.value = `/static/html/gMap.html?lng=${lng}&lat=${lat}&stationData=${params}&${timeStamp}`
}

function getDriving (lng, lat, endLng, endLat) {
	let timeStamp = new Date().getTime()
	Mapview.webUrl.value = `/static/html/gMap.html?lng=${lng}&lat=${lat}&endLng=${endLng}&endLat=${endLat}&${timeStamp}`
}

// 挂载
onLoad(e => {
	const query = JSON.parse(e.query)
	console.log(query)
	// // #ifndef APP-PLUS
	// //h5无法使用uni定位所以传入固定的坐标
	// getStationData(113.335184, 23.126187); 
	// // #endif

	// // #ifdef APP-PLUS
	uni.showLoading({
		title: '获取定位中...'
	})
	uni.getLocation({
		type: 'gcj02',
		success: res => {
			getStationData(res.longitude, res.latitude);
			getDriving(res.longitude, res.latitude, query.currentLo, query.currentLa)
		},
		fail: err => {
			console.log(err);
		},
		complete: (e) => {
			uni.hideLoading()
		}
	})
	// // #endif
})
</script>